# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=spdlog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.1
pkgrel=1
pkgdesc='Very fast, header-only/compiled, C++ logging library (mingw-w64)'
arch=('any')
url='https://github.com/gabime/spdlog'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-fmt")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/gabime/spdlog/archive/v${pkgver}.tar.gz")
sha256sums=('378a040d91f787aec96d269b0c39189f58a6b852e4cbf9150ccfacbe85ebbbfc')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DSPDLOG_BUILD_BENCH=OFF \
    -DSPDLOG_BUILD_EXAMPLE=OFF \
    -DSPDLOG_BUILD_TESTS=ON \
    -DSPDLOG_FMT_EXTERNAL=ON \
    ../${_realname}-${pkgver}

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
